package com.quanyan.ic.common.paging;

/**
 * Created by PythonShi on 2016/6/2.
 */
public class Limit {

    private static int DEFAULT_PAGE_SIZE = 20;

    private int pageSize;

    private int pageNum;

    private int offset;

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public static Limit build(int pageNum, int pageSize) {
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize <= 0) {
            pageSize = DEFAULT_PAGE_SIZE;
        }
        Limit limit = new Limit();
        limit.setOffset((pageNum - 1) * pageSize);
        limit.setPageNum(pageNum);
        limit.setPageSize(pageSize);
        return limit;
    }
}
